from django.db import models
from User.models import User
from goods.models import *
# Create your models here.

class CartItem(models.Model):
    goodsid = models.IntegerField()
    colorid = models.IntegerField()
    sizeid = models.IntegerField()
    count = models.PositiveIntegerField()
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    isdelete = models.BooleanField(default=False)

    class Meta:
        unique_together = ['goodsid', 'colorid', 'sizeid', 'user']

    def goods(self):
        return Goods.objects.get(id=self.goodsid)

    def color(self):
        return Color.objects.get(id=self.colorid)

    def size(self):
        return Size.objects.get(id=self.sizeid)

    def total_price(self):
        return int(self.count) * float(self.goods().price)
